/*
    www.cguage.com
    1.4 数组间的最小距离
*/

#include <iostream>
#include <sstream>
#include <cassert>
#include <vector>
using namespace std;

#ifndef TEST
#define IN(iss) {                       \
        std::string str;                \
        std::getline(std::cin, str);    \
        iss.str(str);                   \
    }
#define OUT(s) std::cout << s
#endif

#define READ_N(iss, n) {    \
    iss >> n;               \
    iss.ignore(1, ',');     \
}

int main() {
    istringstream iss;
    IN(iss);
    assert(!iss.eof());

    string tmp;
    vector<int> v[2];
    for (int i = 0; i < 2; ++i) {
        iss >> tmp;
        istringstream tmpISS(tmp);
        int n = 0;
        while (!tmpISS.eof()) {
            READ_N(tmpISS, n);
            v[i].push_back(n);
        }
    }

    int minLen = 8888888;
    unsigned int i = 0, j = 0;
    while (i < v[0].size() && j < v[1].size()) {
        if (v[0][i] > v[1][j]) {
            minLen = std::min(minLen, v[0][i] - v[1][j]);
            ++j;
        } else {
            minLen = std::min(minLen, v[1][j] - v[0][i]);
            ++i;
        }
    }


    // 结果
    ostringstream oss;
    oss << minLen;
    OUT(oss.str());
    return 0;
}

#ifdef TEST
struct TestCase CASES[] = {
    /*0*/{"1,3,5,7,9 2,6,8", "1"},
    /*1*/{"1,2,3,4,5 1", "0"},
    /*2*/{"1 1,2,3,4,5", "0"},
    /*3*/{"1,3,5,7,9 2,4,6,8,10", "1"},
    /*4*/{"1 2", "1"},
    /*5*/{"1,2,3,4 1,2,3,4", "0"},
    /*6*/{"1,5,7,9,10 3,8,10", "0"},
};
#endif